<?php
include_once 'config/common.php';
if($_REQUEST){
	$data = array('content'=>var_export($_REQUEST,true),'time'=>date('Y-m-d H:i:s'));
	$commonc->insert('test', $data);
}
//$commonc = new common();

$open = fopen('back.log',"a+");	
$str = var_export($_POST,true);
fwrite($open,date("Y-m-d H:i:s")."\r\n".$str."\r\n\r\n");
fclose($open);

$alic = newInstance('alipay');

//支付成功
if($_POST['trade_status']=='TRADE_SUCCESS'){
	$alic->success($_POST['trade_no'] , $_POST['out_trade_no']);
	echo 'success';
}

//交易完成
if($_POST['trade_status'] == 'TRADE_FINISHED'){
	$alic->success($_POST['trade_no'] , $_POST['out_trade_no']  , 'finished');
	echo 'success';
}

//退款成功1
if($_POST['refund_status'] == 'REFUND_SUCCESS'){
	$trade_no = $_POST['trade_no'];
	$alic->success($trade_no , $_POST['batch_no'] , 'refund');
	$open = fopen('back.log',"a+");
	$strr = '这是REFUND_SUCCESS的数据';
	fwrite($open,date("Y-m-d H:i:s")."\r\n".$strr."\r\n\r\n");
	fclose($open);
	echo 'success';
}

//退款成功2
if($_POST['success_num'] > 0){
	$details = $_POST['result_details'];
	$arr = explode("^", $details);
	if($arr['2'] == 'SUCCESS'){
		$trade_no = $arr['0'];
	}
	$open = fopen('back.log',"a+");
	$strr = '这是success_num的数据';
	fwrite($open,date("Y-m-d H:i:s")."\r\n".$strr."\r\n\r\n");
	fclose($open);
	$alic->success($trade_no , $_POST['batch_no'] , 'refund');
	echo 'success';
}

?>